﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var userMoney;
    $(function () {
        getProperty();
        $("#ReceiveUserAccount").blur(function () {
            if ($("#ReceiveUserAccount").val() == '')
                return;
            $.ajax({
                url: "/BizManage/UserGive/GetReceiveName?receiveAccount=" + $("#ReceiveUserAccount").val(),
                success: function (result) {
                    var data = eval('(' + result + ')');
                    if (data.receiveName == '') {
                        alert("账号为：“" + $("#ReceiveUserAccount").val() + "”的代理商不存在，请重新输入！");
                        return;
                    }
                    $('#ReceiveUserName').val(data.receiveName);
                }
            });
        });
    });
    
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var userProperty = $('#UserProperty').val();
        var money = $('#GiveCount').val();
        if (parseFloat(money).toFixed(2) > parseFloat(userProperty).toFixed(2)) {
            alert("请重新输入赠送积分数量！");
            return;
        }
        $.submitForm({
            url: "/BizManage/UserGive/SubmitForm",
            param: $("#form1").formSerialize(),
            success: function() {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });
    }

    //获取供货商资产信息
    function getProperty() {
        $.ajax({
            url: "/MemberManage/MemberWithdrawals/GetProperty",
            success: function (result) {
                var data = eval('(' + result + ')');
                $('#UserProperty').val(data.userProperty);
                userMoney = data.userProperty;
            }
        });
    }

</script>
<form id="form1">
    <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
        <div style="padding-top: 20px; margin-right: 30px;">
            <table class="form">
                <tr>
                    <th class="formTitle">积分余额</th>
                    <td class="formValue" colspan="3">
                        <input id="UserProperty"  type="text" class="form-control required" disabled="disabled"  />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">接收人账号</th>
                    <td class="formValue" colspan="2">
                        <input id="ReceiveUserAccount" name="ReceiveUserAccount" type="text" class="form-control required" placeholder="请输入接收人账号"/>
                    </td>
                    <th class="formTitle">接收人</th>
                    <td class="formValue" >
                        <input id="ReceiveUserName"  type="text" class="form-control " disabled="disabled"  />
                    </td>
                </tr>

                <tr>
                    <th class="formTitle">赠送数量</th>
                    <td class="formValue" colspan="3">
                        <input id="GiveCount" name="GiveCount" type="text" class="form-control required number" placeholder="请输入赠送数量"/>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 5px;">
                        备注
                    </th>
                    <td class="formValue" colspan="3">
                        <textarea id="Remarks" name="Remarks" class="form-control" style="height: 60px;"></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</form>
